package org.example.springboot01.controller;


import org.example.springboot01.pojo.Category;
import org.example.springboot01.pojo.Result;
import org.example.springboot01.service.Categoryservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class Categorycontroller {
    //实现添加分类
    @Autowired
    private Categoryservice categoreservice;
    @PostMapping
    public Result addcatepory(@RequestBody Category categoryname){
        categoreservice.addcategory(categoryname);
        return Result.success("添加成功！");
    }
    //实现查询用户添加的分类
    @GetMapping("/getbyuser")
    public Result<List<Category>> getcategory(){
        List<Category> list = categoreservice.getcategory();
        return Result.success(list);
    }
    //实现根据id查询分类
    @GetMapping("/getbyid")
    public Result<List<Category>> getcategorybyid(@RequestParam Integer id){
        List<Category> list = categoreservice.getcategorybyid(id);
        return Result.success(list);
    }
    //实现更新文章
    @PutMapping
    public Result updatecategory(@RequestBody Category category){
        categoreservice.updatecategory(category);
        return Result.success("更新成功");
    }
    //实现删除文章
    @DeleteMapping
    public Result deletecategory(@RequestParam String name){
        categoreservice.deletecategory(name);
        return Result.success("删除成功");
    }


}
